/*
 * @Author: 彭林
 * @Date: 2020-12-25 14:52:03
 * @LastEditTime: 2021-07-01 15:25:30
 * @LastEditors: 彭林
 * @Description:
 * @FilePath: /src/saas-app/app/api/v1/peotry.go
 */
package v1

import (
	"saas-app/app/define"
	"saas-app/app/model"
	"saas-app/app/service"
	"saas-app/library/response"

	"github.com/gogf/gf/net/ghttp"
)

func CreatePeotry(r *ghttp.Request) {

	var params define.PeotryParams
	if err := r.Parse(&params); err != nil {
		response.JsonExit(r, 1, err.Error())
	}

	var modelPeotry model.Peotry
	modelPeotry.Align = params.Align
	modelPeotry.Appreciate = params.Appreciate
	modelPeotry.Author = params.Author
	modelPeotry.AuthorMore = params.AuthorMore
	modelPeotry.DuYin = params.DuYin
	modelPeotry.OrgText = params.OrgText
	modelPeotry.PeotryId = params.PeotryId
	modelPeotry.Reason = params.Reason
	modelPeotry.Title = params.Title
	modelPeotry.Translation = params.Translation
	modelPeotry.Video = params.Video
	modelPeotry.Years = params.Years

	re := service.PeotryService().CreatePeotry(&modelPeotry, params.NoteList)

	if re == 0 {
		panic("创建失败")
	}

	response.JsonExit(r, 0, "创建成功", re)
}

func GetPeotryLastId(r *ghttp.Request) {
	id := service.PeotryService().GetPeotryLastId()
	response.JsonExit(r, 0, "诗词id", id)
}

func GetPeotryList(r *ghttp.Request) {

	page := r.GetQueryInt("page")
	limit := r.GetQueryInt("limit")

	result, total := service.PeotryService().GetPeotryList(page, limit)
	response.JsonExit(r, 0, "诗词列表", response.Paging(result, total, page, limit))
}

func GetPeotryInfo(r *ghttp.Request) {
	peotry_id := r.GetFormUint("peotry_id")
	data := service.PeotryService().GetInfo(peotry_id)
	response.JsonExit(r, 0, "诗词详情", data)
}
